import { userProfilesApi } from "@/request/Api"
export default {
    namespaced: true,
    state: {
        userinfo: {
            // 头像
            headImg: require("@/assets/img/monad.png"),
            // 昵称
            nickName: "游客",
            // 积分
            coin: 0,
        },
        cartTotal: 0,
    },
    mutations: {
        updateUserInfo(state, payload) {
            state.userinfo = payload.userInfo;
            state.cartTotal = payload.cartTotal;
        },
        initUserInfo(state) {
            state.userinfo.headImg = require("@/assets/img/userImg.f8bbec5e.png")
            state.userinfo.nickName = "--",
                state.userinfo.coin = "--",
                state.cartTotal = 0
        }
    },
    actions: {
        async asyncUpdateUserInfo({ commit }) {
            let userProfilesRes = await userProfilesApi();
            console.log({ userProfilesRes });
            commit('updateUserInfo', userProfilesRes.data)
        }
    }
}